/*
 *http://www.apache.org/licenses/LICENSE-2.0
 *Copyright (c) 2021 fullset
 *@ClassName SysUserController
 *@date 2021/5/29 16:32
 *@Description TODO
 */
package com.fs.base.controller;

import com.fs.base.service.SysUserService;
import com.fs.core.web.BaseResult;
import com.fs.orm.entity.SysUser;
import com.fs.orm.vo.form.SysUserForm;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags="用户服务接口")
@RestController
@RequestMapping("/baseService/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "用户列表", notes = "")
    @PostMapping(value ="/layTable")
    public BaseResult<List<SysUser>> getLayTable(@RequestBody Map<String, Object> params) {
        PageInfo<SysUser> pageInfo = sysUserService.getLayTable(params);
        Long count = pageInfo.getTotal();
        return new BaseResult<>(count.intValue(), pageInfo.getList());
    }

    @ApiOperation(value="初始化用户表单")
    @PostMapping("/initForm")
    public BaseResult<SysUserForm> initForm() {
        return new BaseResult<>(sysUserService.initForm());
    }

    @ApiOperation(value="编辑用户表单")
    @PostMapping("/editForm/{id}")
    public BaseResult<SysUserForm> editForm(@PathVariable Long id) {
        return new BaseResult<>(sysUserService.editForm(id));
    }

    @ApiOperation(value = "添加用户", notes = "")
    @PostMapping(value ="/addUser")
    public BaseResult<SysUserForm> addUser(@RequestBody SysUserForm sysUserForm) throws Exception {
        return new BaseResult<>(sysUserService.addUser(sysUserForm));
    }

    @ApiOperation(value = "删除用户", notes = "逻辑删除")
    @PostMapping(value ="/logicalDel/{id}")
    public BaseResult<Boolean> logicalDel(@PathVariable String id)  {
        return new BaseResult<>(sysUserService.logicalDeleteById(id));
    }

    @ApiOperation(value = "批量删除用户", notes = "逻辑删除")
    @PostMapping(value ="/batchDel/{ids}")
    public BaseResult<Boolean> batchDel(@PathVariable String ids)  {
        return new BaseResult<>(sysUserService.batchDel(ids));
    }

    @ApiOperation(value = "编辑用户", notes = "")
    @PostMapping(value ="/editUser")
    public BaseResult<SysUserForm> editUser(@RequestBody SysUserForm sysUserForm) {
        return new BaseResult<>(sysUserService.editUser(sysUserForm));
    }
}
